#ifndef THINK_THINK_VALIDATE_H
#define THINK_THINK_VALIDATE_H

static char* think_validate =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: liu21st <liu21st@gmail.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think;\n"
	"\n"
	"use think\\exception\\ClassNotFoundException;\n"
	"\n"
	"class Validate\n"
	"{\n"
	"    // 实例\n"
	"    protected static $instance;\n"
	"\n"
	"    // 自定义的验证类型\n"
	"    protected static $type = [];\n"
	"\n"
	"    // 验证类型别名\n"
	"    protected $alias = [\n"
	"        \'>\' => \'gt\', \'>=\' => \'egt\', \'<\' => \'lt\', \'<=\' => \'elt\', \'=\' => \'eq\', \'same\' => \'eq\',\n"
	"    ];\n"
	"\n"
	"    // 当前验证的规则\n"
	"    protected $rule = [];\n"
	"\n"
	"    // 验证提示信息\n"
	"    protected $message = [];\n"
	"    // 验证字段描述\n"
	"    protected $field = [];\n"
	"\n"
	"    // 验证规则默认提示信息\n"
	"    protected static $typeMsg = [\n"
	"        \'require\'     => \':attribute require\',\n"
	"        \'number\'      => \':attribute must be numeric\',\n"
	"        \'integer\'     => \':attribute must be integer\',\n"
	"        \'float\'       => \':attribute must be float\',\n"
	"        \'boolean\'     => \':attribute must be bool\',\n"
	"        \'email\'       => \':attribute not a valid email address\',\n"
	"        \'array\'       => \':attribute must be a array\',\n"
	"        \'accepted\'    => \':attribute must be yes,on or 1\',\n"
	"        \'date\'        => \':attribute not a valid datetime\',\n"
	"        \'file\'        => \':attribute not a valid file\',\n"
	"        \'image\'       => \':attribute not a valid image\',\n"
	"        \'alpha\'       => \':attribute must be alpha\',\n"
	"        \'alphaNum\'    => \':attribute must be alpha-numeric\',\n"
	"        \'alphaDash\'   => \':attribute must be alpha-numeric, dash, underscore\',\n"
	"        \'activeUrl\'   => \':attribute not a valid domain or ip\',\n"
	"        \'chs\'         => \':attribute must be chinese\',\n"
	"        \'chsAlpha\'    => \':attribute must be chinese or alpha\',\n"
	"        \'chsAlphaNum\' => \':attribute must be chinese,alpha-numeric\',\n"
	"        \'chsDash\'     => \':attribute must be chinese,alpha-numeric,underscore, dash\',\n"
	"        \'url\'         => \':attribute not a valid url\',\n"
	"        \'ip\'          => \':attribute not a valid ip\',\n"
	"        \'dateFormat\'  => \':attribute must be dateFormat of :rule\',\n"
	"        \'in\'          => \':attribute must be in :rule\',\n"
	"        \'notIn\'       => \':attribute be notin :rule\',\n"
	"        \'between\'     => \':attribute must between :1 - :2\',\n"
	"        \'notBetween\'  => \':attribute not between :1 - :2\',\n"
	"        \'length\'      => \'size of :attribute must be :rule\',\n"
	"        \'max\'         => \'max size of :attribute must be :rule\',\n"
	"        \'min\'         => \'min size of :attribute must be :rule\',\n"
	"        \'after\'       => \':attribute cannot be less than :rule\',\n"
	"        \'before\'      => \':attribute cannot exceed :rule\',\n"
	"        \'afterWith\'   => \':attribute cannot be less than :rule\',\n"
	"        \'beforeWith\'  => \':attribute cannot exceed :rule\',\n"
	"        \'expire\'      => \':attribute not within :rule\',\n"
	"        \'allowIp\'     => \'access IP is not allowed\',\n"
	"        \'denyIp\'      => \'access IP denied\',\n"
	"        \'confirm\'     => \':attribute out of accord with :2\',\n"
	"        \'different\'   => \':attribute cannot be same with :2\',\n"
	"        \'egt\'         => \':attribute must greater than or equal :rule\',\n"
	"        \'gt\'          => \':attribute must greater than :rule\',\n"
	"        \'elt\'         => \':attribute must less than or equal :rule\',\n"
	"        \'lt\'          => \':attribute must less than :rule\',\n"
	"        \'eq\'          => \':attribute must equal :rule\',\n"
	"        \'unique\'      => \':attribute has exists\',\n"
	"        \'regex\'       => \':attribute not conform to the rules\',\n"
	"        \'method\'      => \'invalid Request method\',\n"
	"        \'token\'       => \'invalid token\',\n"
	"        \'fileSize\'    => \'filesize not match\',\n"
	"        \'fileExt\'     => \'extensions to upload is not allowed\',\n"
	"        \'fileMime\'    => \'mimetype to upload is not allowed\',\n"
	"    ];\n"
	"\n"
	"    // 当前验证场景\n"
	"    protected $currentScene = null;\n"
	"\n"
	"    // 正则表达式 regex = [\'zip\'=>\'\\d{6}\',...]\n"
	"    protected $regex = [];\n"
	"\n"
	"    // 验证场景 scene = [\'edit\'=>\'name1,name2,...\']\n"
	"    protected $scene = [];\n"
	"\n"
	"    // 验证失败错误信息\n"
	"    protected $error = [];\n"
	"\n"
	"    // 批量验证\n"
	"    protected $batch = false;\n"
	"\n"
	"    /**\n"
	"     * 构造函数\n"
	"     * @access public\n"
	"     * @param array $rules 验证规则\n"
	"     * @param array $message 验证提示信息\n"
	"     * @param array $field 验证字段描述信息\n"
	"     */\n"
	"    public function __construct(array $rules = [], $message = [], $field = [])\n"
	"    {\n"
	"        $this->rule    = array_merge($this->rule, $rules);\n"
	"        $this->message = array_merge($this->message, $message);\n"
	"        $this->field   = array_merge($this->field, $field);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 实例化验证\n"
	"     * @access public\n"
	"     * @param array     $rules 验证规则\n"
	"     * @param array     $message 验证提示信息\n"
	"     * @param array     $field 验证字段描述信息\n"
	"     * @return Validate\n"
	"     */\n"
	"    public static function make($rules = [], $message = [], $field = [])\n"
	"    {\n"
	"        if (is_null(self::$instance)) {\n"
	"            self::$instance = new self($rules, $message, $field);\n"
	"        }\n"
	"        return self::$instance;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 添加字段验证规则\n"
	"     * @access protected\n"
	"     * @param string|array  $name  字段名称或者规则数组\n"
	"     * @param mixed         $rule  验证规则\n"
	"     * @return Validate\n"
	"     */\n"
	"    public function rule($name, $rule = \'\')\n"
	"    {\n"
	"        if (is_array($name)) {\n"
	"            $this->rule = array_merge($this->rule, $name);\n"
	"        } else {\n"
	"            $this->rule[$name] = $rule;\n"
	"        }\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 注册验证（类型）规则\n"
	"     * @access public\n"
	"     * @param string    $type  验证规则类型\n"
	"     * @param mixed     $callback callback方法(或闭包)\n"
	"     * @return void\n"
	"     */\n"
	"    public static function extend($type, $callback = null)\n"
	"    {\n"
	"        if (is_array($type)) {\n"
	"            self::$type = array_merge(self::$type, $type);\n"
	"        } else {\n"
	"            self::$type[$type] = $callback;\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 设置验证规则的默认提示信息\n"
	"     * @access protected\n"
	"     * @param string|array  $type  验证规则类型名称或者数组\n"
	"     * @param string        $msg  验证提示信息\n"
	"     * @return void\n"
	"     */\n"
	"    public static function setTypeMsg($type, $msg = null)\n"
	"    {\n"
	"        if (is_array($type)) {\n"
	"            self::$typeMsg = array_merge(self::$typeMsg, $type);\n"
	"        } else {\n"
	"            self::$typeMsg[$type] = $msg;\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 设置提示信息\n"
	"     * @access public\n"
	"     * @param string|array  $name  字段名称\n"
	"     * @param string        $message 提示信息\n"
	"     * @return Validate\n"
	"     */\n"
	"    public function message($name, $message = \'\')\n"
	"    {\n"
	"        if (is_array($name)) {\n"
	"            $this->message = array_merge($this->message, $name);\n"
	"        } else {\n"
	"            $this->message[$name] = $message;\n"
	"        }\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 设置验证场景\n"
	"     * @access public\n"
	"     * @param string|array  $name  场景名或者场景设置数组\n"
	"     * @param mixed         $fields 要验证的字段\n"
	"     * @return Validate\n"
	"     */\n"
	"    public function scene($name, $fields = null)\n"
	"    {\n"
	"        if (is_array($name)) {\n"
	"            $this->scene = array_merge($this->scene, $name);\n"
	"        }if (is_null($fields)) {\n"
	"            // 设置当前场景\n"
	"            $this->currentScene = $name;\n"
	"        } else {\n"
	"            // 设置验证场景\n"
	"            $this->scene[$name] = $fields;\n"
	"        }\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 判断是否存在某个验证场景\n"
	"     * @access public\n"
	"     * @param string $name 场景名\n"
	"     * @return bool\n"
	"     */\n"
	"    public function hasScene($name)\n"
	"    {\n"
	"        return isset($this->scene[$name]);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 设置批量验证\n"
	"     * @access public\n"
	"     * @param bool $batch  是否批量验证\n"
	"     * @return Validate\n"
	"     */\n"
	"    public function batch($batch = true)\n"
	"    {\n"
	"        $this->batch = $batch;\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 数据自动验证\n"
	"     * @access public\n"
	"     * @param array     $data  数据\n"
	"     * @param mixed     $rules  验证规则\n"
	"     * @param string    $scene 验证场景\n"
	"     * @return bool\n"
	"     */\n"
	"    public function check($data, $rules = [], $scene = \'\')\n"
	"    {\n"
	"        $this->error = [];\n"
	"\n"
	"        if (empty($rules)) {\n"
	"            // 读取验证规则\n"
	"            $rules = $this->rule;\n"
	"        }\n"
	"\n"
	"        // 分析验证规则\n"
	"        $scene = $this->getScene($scene);\n"
	"        if (is_array($scene)) {\n"
	"            // 处理场景验证字段\n"
	"            $change = [];\n"
	"            $array  = [];\n"
	"            foreach ($scene as $k => $val) {\n"
	"                if (is_numeric($k)) {\n"
	"                    $array[] = $val;\n"
	"                } else {\n"
	"                    $array[]    = $k;\n"
	"                    $change[$k] = $val;\n"
	"                }\n"
	"            }\n"
	"        }\n"
	"\n"
	"        foreach ($rules as $key => $item) {\n"
	"            // field => rule1|rule2... field=>[\'rule1\',\'rule2\',...]\n"
	"            if (is_numeric($key)) {\n"
	"                // [field,rule1|rule2,msg1|msg2]\n"
	"                $key  = $item[0];\n"
	"                $rule = $item[1];\n"
	"                if (isset($item[2])) {\n"
	"                    $msg = is_string($item[2]) ? explode(\'|\', $item[2]) : $item[2];\n"
	"                } else {\n"
	"                    $msg = [];\n"
	"                }\n"
	"            } else {\n"
	"                $rule = $item;\n"
	"                $msg  = [];\n"
	"            }\n"
	"            if (strpos($key, \'|\')) {\n"
	"                // 字段|描述 用于指定属性名称\n"
	"                list($key, $title) = explode(\'|\', $key);\n"
	"            } else {\n"
	"                $title = isset($this->field[$key]) ? $this->field[$key] : $key;\n"
	"            }\n"
	"\n"
	"            // 场景检测\n"
	"            if (!empty($scene)) {\n"
	"                if ($scene instanceof \\Closure && !call_user_func_array($scene, [$key, $data])) {\n"
	"                    continue;\n"
	"                } elseif (is_array($scene)) {\n"
	"                    if (!in_array($key, $array)) {\n"
	"                        continue;\n"
	"                    } elseif (isset($change[$key])) {\n"
	"                        // 重载某个验证规则\n"
	"                        $rule = $change[$key];\n"
	"                    }\n"
	"                }\n"
	"            }\n"
	"\n"
	"            // 获取数据 支持二维数组\n"
	"            $value = $this->getDataValue($data, $key);\n"
	"\n"
	"            // 字段验证\n"
	"            if ($rule instanceof \\Closure) {\n"
	"                // 匿名函数验证 支持传入当前字段和所有字段两个数据\n"
	"                $result = call_user_func_array($rule, [$value, $data]);\n"
	"            } else {\n"
	"                $result = $this->checkItem($key, $value, $rule, $data, $title, $msg);\n"
	"            }\n"
	"\n"
	"            if (true !== $result) {\n"
	"                // 没有返回true 则表示验证失败\n"
	"                if (!empty($this->batch)) {\n"
	"                    // 批量验证\n"
	"                    if (is_array($result)) {\n"
	"                        $this->error = array_merge($this->error, $result);\n"
	"                    } else {\n"
	"                        $this->error[$key] = $result;\n"
	"                    }\n"
	"                } else {\n"
	"                    $this->error = $result;\n"
	"                    return false;\n"
	"                }\n"
	"            }\n"
	"        }\n"
	"        return !empty($this->error) ? false : true;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 根据验证规则验证数据\n"
	"     * @access protected\n"
	"     * @param  mixed     $value 字段值\n"
	"     * @param  mixed     $rules 验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function checkRule($value, $rules)\n"
	"    {\n"
	"        if ($rules instanceof \\Closure) {\n"
	"            return call_user_func_array($rules, [$value]);\n"
	"        } elseif (is_string($rules)) {\n"
	"            $rules = explode(\'|\', $rules);\n"
	"        }\n"
	"\n"
	"        foreach ($rules as $key => $rule) {\n"
	"            if ($rule instanceof \\Closure) {\n"
	"                $result = call_user_func_array($rule, [$value]);\n"
	"            } else {\n"
	"                // 判断验证类型\n"
	"                list($type, $rule) = $this->getValidateType($key, $rule);\n"
	"\n"
	"                $callback = isset(self::$type[$type]) ? self::$type[$type] : [$this, $type];\n"
	"\n"
	"                $result = call_user_func_array($callback, [$value, $rule]);\n"
	"            }\n"
	"\n"
	"            if (true !== $result) {\n"
	"                return $result;\n"
	"            }\n"
	"        }\n"
	"\n"
	"        return true;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证单个字段规则\n"
	"     * @access protected\n"
	"     * @param string    $field  字段名\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rules  验证规则\n"
	"     * @param array     $data  数据\n"
	"     * @param string    $title  字段描述\n"
	"     * @param array     $msg  提示信息\n"
	"     * @return mixed\n"
	"     */\n"
	"    protected function checkItem($field, $value, $rules, $data, $title = \'\', $msg = [])\n"
	"    {\n"
	"        // 支持多规则验证 require|in:a,b,c|... 或者 [\'require\',\'in\'=>\'a,b,c\',...]\n"
	"        if (is_string($rules)) {\n"
	"            $rules = explode(\'|\', $rules);\n"
	"        }\n"
	"        $i = 0;\n"
	"        foreach ($rules as $key => $rule) {\n"
	"            if ($rule instanceof \\Closure) {\n"
	"                $result = call_user_func_array($rule, [$value, $data]);\n"
	"                $info   = is_numeric($key) ? \'\' : $key;\n"
	"            } else {\n"
	"                // 判断验证类型\n"
	"                list($type, $rule, $info) = $this->getValidateType($key, $rule);\n"
	"\n"
	"                // 如果不是require 有数据才会行验证\n"
	"                if (0 === strpos($info, \'require\') || (!is_null($value) && \'\' !== $value)) {\n"
	"                    // 验证类型\n"
	"                    $callback = isset(self::$type[$type]) ? self::$type[$type] : [$this, $type];\n"
	"                    // 验证数据\n"
	"                    $result = call_user_func_array($callback, [$value, $rule, $data, $field, $title]);\n"
	"                } else {\n"
	"                    $result = true;\n"
	"                }\n"
	"            }\n"
	"\n"
	"            if (false === $result) {\n"
	"                // 验证失败 返回错误信息\n"
	"                if (isset($msg[$i])) {\n"
	"                    $message = $msg[$i];\n"
	"                    if (is_string($message) && strpos($message, \'{%\') === 0) {\n"
	"                        $message = Lang::get(substr($message, 2, -1));\n"
	"                    }\n"
	"                } else {\n"
	"                    $message = $this->getRuleMsg($field, $title, $info, $rule);\n"
	"                }\n"
	"                return $message;\n"
	"            } elseif (true !== $result) {\n"
	"                // 返回自定义错误信息\n"
	"                if (is_string($result) && false !== strpos($result, \':\')) {\n"
	"                    $result = str_replace([\':attribute\', \':rule\'], [$title, (string) $rule], $result);\n"
	"                }\n"
	"                return $result;\n"
	"            }\n"
	"            $i++;\n"
	"        }\n"
	"        return $result;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取当前验证类型及规则\n"
	"     * @access public\n"
	"     * @param  mixed     $key\n"
	"     * @param  mixed     $rule\n"
	"     * @return array\n"
	"     */\n"
	"    protected function getValidateType($key, $rule)\n"
	"    {\n"
	"        // 判断验证类型\n"
	"        if (!is_numeric($key)) {\n"
	"            return [$key, $rule, $key];\n"
	"        }\n"
	"\n"
	"        if (strpos($rule, \':\')) {\n"
	"            list($type, $rule) = explode(\':\', $rule, 2);\n"
	"            if (isset($this->alias[$type])) {\n"
	"                // 判断别名\n"
	"                $type = $this->alias[$type];\n"
	"            }\n"
	"            $info = $type;\n"
	"        } elseif (method_exists($this, $rule)) {\n"
	"            $type = $rule;\n"
	"            $info = $rule;\n"
	"            $rule = \'\';\n"
	"        } else {\n"
	"            $type = \'is\';\n"
	"            $info = $rule;\n"
	"        }\n"
	"\n"
	"        return [$type, $rule, $info];\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证是否和某个字段的值一致\n"
	"     * @access protected\n"
	"     * @param mixed     $value 字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @param array     $data  数据\n"
	"     * @param string    $field 字段名\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function confirm($value, $rule, $data, $field = \'\')\n"
	"    {\n"
	"        if (\'\' == $rule) {\n"
	"            if (strpos($field, \'_confirm\')) {\n"
	"                $rule = strstr($field, \'_confirm\', true);\n"
	"            } else {\n"
	"                $rule = $field . \'_confirm\';\n"
	"            }\n"
	"        }\n"
	"        return $this->getDataValue($data, $rule) === $value;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证是否和某个字段的值是否不同\n"
	"     * @access protected\n"
	"     * @param mixed $value 字段值\n"
	"     * @param mixed $rule  验证规则\n"
	"     * @param array $data  数据\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function different($value, $rule, $data)\n"
	"    {\n"
	"        return $this->getDataValue($data, $rule) != $value;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证是否大于等于某个值\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @param array     $data  数据\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function egt($value, $rule, $data)\n"
	"    {\n"
	"        $val = $this->getDataValue($data, $rule);\n"
	"        return !is_null($val) && $value >= $val;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证是否大于某个值\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @param array     $data  数据\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function gt($value, $rule, $data)\n"
	"    {\n"
	"        $val = $this->getDataValue($data, $rule);\n"
	"        return !is_null($val) && $value > $val;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证是否小于等于某个值\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @param array     $data  数据\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function elt($value, $rule, $data)\n"
	"    {\n"
	"        $val = $this->getDataValue($data, $rule);\n"
	"        return !is_null($val) && $value <= $val;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证是否小于某个值\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @param array     $data  数据\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function lt($value, $rule, $data)\n"
	"    {\n"
	"        $val = $this->getDataValue($data, $rule);\n"
	"        return !is_null($val) && $value < $val;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证是否等于某个值\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function eq($value, $rule)\n"
	"    {\n"
	"        return $value == $rule;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证字段值是否为有效格式\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param string    $rule  验证规则\n"
	"     * @param array     $data  验证数据\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function is($value, $rule, $data = [])\n"
	"    {\n"
	"        switch ($rule) {\n"
	"            case \'require\':\n"
	"                // 必须\n"
	"                $result = !empty($value) || \'0\' == $value;\n"
	"                break;\n"
	"            case \'accepted\':\n"
	"                // 接受\n"
	"                $result = in_array($value, [\'1\', \'on\', \'yes\']);\n"
	"                break;\n"
	"            case \'date\':\n"
	"                // 是否是一个有效日期\n"
	"                $result = false !== strtotime($value);\n"
	"                break;\n"
	"            case \'alpha\':\n"
	"                // 只允许字母\n"
	"                $result = $this->regex($value, \'/^[A-Za-z]+$/\');\n"
	"                break;\n"
	"            case \'alphaNum\':\n"
	"                // 只允许字母和数字\n"
	"                $result = $this->regex($value, \'/^[A-Za-z0-9]+$/\');\n"
	"                break;\n"
	"            case \'alphaDash\':\n"
	"                // 只允许字母、数字和下划线 破折号\n"
	"                $result = $this->regex($value, \'/^[A-Za-z0-9\\-\\_]+$/\');\n"
	"                break;\n"
	"            case \'chs\':\n"
	"                // 只允许汉字\n"
	"                $result = $this->regex($value, \'/^[\\x{4e00}-\\x{9fa5}]+$/u\');\n"
	"                break;\n"
	"            case \'chsAlpha\':\n"
	"                // 只允许汉字、字母\n"
	"                $result = $this->regex($value, \'/^[\\x{4e00}-\\x{9fa5}a-zA-Z]+$/u\');\n"
	"                break;\n"
	"            case \'chsAlphaNum\':\n"
	"                // 只允许汉字、字母和数字\n"
	"                $result = $this->regex($value, \'/^[\\x{4e00}-\\x{9fa5}a-zA-Z0-9]+$/u\');\n"
	"                break;\n"
	"            case \'chsDash\':\n"
	"                // 只允许汉字、字母、数字和下划线_及破折号-\n"
	"                $result = $this->regex($value, \'/^[\\x{4e00}-\\x{9fa5}a-zA-Z0-9\\_\\-]+$/u\');\n"
	"                break;\n"
	"            case \'activeUrl\':\n"
	"                // 是否为有效的网址\n"
	"                $result = checkdnsrr($value);\n"
	"                break;\n"
	"            case \'ip\':\n"
	"                // 是否为IP地址\n"
	"                $result = $this->filter($value, [FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6]);\n"
	"                break;\n"
	"            case \'url\':\n"
	"                // 是否为一个URL地址\n"
	"                $result = $this->filter($value, FILTER_VALIDATE_URL);\n"
	"                break;\n"
	"            case \'float\':\n"
	"                // 是否为float\n"
	"                $result = $this->filter($value, FILTER_VALIDATE_FLOAT);\n"
	"                break;\n"
	"            case \'number\':\n"
	"                $result = is_numeric($value);\n"
	"                break;\n"
	"            case \'integer\':\n"
	"                // 是否为整型\n"
	"                $result = $this->filter($value, FILTER_VALIDATE_INT);\n"
	"                break;\n"
	"            case \'email\':\n"
	"                // 是否为邮箱地址\n"
	"                $result = $this->filter($value, FILTER_VALIDATE_EMAIL);\n"
	"                break;\n"
	"            case \'boolean\':\n"
	"                // 是否为布尔值\n"
	"                $result = in_array($value, [true, false, 0, 1, \'0\', \'1\'], true);\n"
	"                break;\n"
	"            case \'array\':\n"
	"                // 是否为数组\n"
	"                $result = is_array($value);\n"
	"                break;\n"
	"            case \'file\':\n"
	"                $result = $value instanceof File;\n"
	"                break;\n"
	"            case \'image\':\n"
	"                $result = $value instanceof File && in_array($this->getImageType($value->getRealPath()), [1, 2, 3, 6]);\n"
	"                break;\n"
	"            case \'token\':\n"
	"                $result = $this->token($value, \'__token__\', $data);\n"
	"                break;\n"
	"            default:\n"
	"                if (isset(self::$type[$rule])) {\n"
	"                    // 注册的验证规则\n"
	"                    $result = call_user_func_array(self::$type[$rule], [$value]);\n"
	"                } else {\n"
	"                    // 正则验证\n"
	"                    $result = $this->regex($value, $rule);\n"
	"                }\n"
	"        }\n"
	"        return $result;\n"
	"    }\n"
	"\n"
	"    // 判断图像类型\n"
	"    protected function getImageType($image)\n"
	"    {\n"
	"        if (function_exists(\'exif_imagetype\')) {\n"
	"            return exif_imagetype($image);\n"
	"        } else {\n"
	"            try {\n"
	"                $info = getimagesize($image);\n"
	"                return $info ? $info[2] : false;\n"
	"            } catch (\\Exception $e) {\n"
	"                return false;\n"
	"            }\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证是否为合格的域名或者IP 支持A，MX，NS，SOA，PTR，CNAME，AAAA，A6， SRV，NAPTR，TXT 或者 ANY类型\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function activeUrl($value, $rule)\n"
	"    {\n"
	"        if (!in_array($rule, [\'A\', \'MX\', \'NS\', \'SOA\', \'PTR\', \'CNAME\', \'AAAA\', \'A6\', \'SRV\', \'NAPTR\', \'TXT\', \'ANY\'])) {\n"
	"            $rule = \'MX\';\n"
	"        }\n"
	"        return checkdnsrr($value, $rule);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证是否有效IP\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则 ipv4 ipv6\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function ip($value, $rule)\n"
	"    {\n"
	"        if (!in_array($rule, [\'ipv4\', \'ipv6\'])) {\n"
	"            $rule = \'ipv4\';\n"
	"        }\n"
	"        return $this->filter($value, [FILTER_VALIDATE_IP, \'ipv6\' == $rule ? FILTER_FLAG_IPV6 : FILTER_FLAG_IPV4]);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证上传文件后缀\n"
	"     * @access protected\n"
	"     * @param mixed     $file  上传文件\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function fileExt($file, $rule)\n"
	"    {\n"
	"        if (is_array($file)) {\n"
	"            foreach ($file as $item) {\n"
	"                if (!($item instanceof File) || !$item->checkExt($rule)) {\n"
	"                    return false;\n"
	"                }\n"
	"            }\n"
	"            return true;\n"
	"        } elseif ($file instanceof File) {\n"
	"            return $file->checkExt($rule);\n"
	"        } else {\n"
	"            return false;\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证上传文件类型\n"
	"     * @access protected\n"
	"     * @param mixed     $file  上传文件\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function fileMime($file, $rule)\n"
	"    {\n"
	"        if (is_array($file)) {\n"
	"            foreach ($file as $item) {\n"
	"                if (!($item instanceof File) || !$item->checkMime($rule)) {\n"
	"                    return false;\n"
	"                }\n"
	"            }\n"
	"            return true;\n"
	"        } elseif ($file instanceof File) {\n"
	"            return $file->checkMime($rule);\n"
	"        } else {\n"
	"            return false;\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证上传文件大小\n"
	"     * @access protected\n"
	"     * @param mixed     $file  上传文件\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function fileSize($file, $rule)\n"
	"    {\n"
	"        if (is_array($file)) {\n"
	"            foreach ($file as $item) {\n"
	"                if (!($item instanceof File) || !$item->checkSize($rule)) {\n"
	"                    return false;\n"
	"                }\n"
	"            }\n"
	"            return true;\n"
	"        } elseif ($file instanceof File) {\n"
	"            return $file->checkSize($rule);\n"
	"        } else {\n"
	"            return false;\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证图片的宽高及类型\n"
	"     * @access protected\n"
	"     * @param mixed     $file  上传文件\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function image($file, $rule)\n"
	"    {\n"
	"        if (!($file instanceof File)) {\n"
	"            return false;\n"
	"        }\n"
	"        if ($rule) {\n"
	"            $rule                        = explode(\',\', $rule);\n"
	"            list($width, $height, $type) = getimagesize($file->getRealPath());\n"
	"            if (isset($rule[2])) {\n"
	"                $imageType = strtolower($rule[2]);\n"
	"                if (\'jpeg\' == $imageType) {\n"
	"                    $imageType = \'jpg\';\n"
	"                }\n"
	"                if (image_type_to_extension($type, false) != $imageType) {\n"
	"                    return false;\n"
	"                }\n"
	"            }\n"
	"\n"
	"            list($w, $h) = $rule;\n"
	"            return $w == $width && $h == $height;\n"
	"        } else {\n"
	"            return in_array($this->getImageType($file->getRealPath()), [1, 2, 3, 6]);\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证请求类型\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function method($value, $rule)\n"
	"    {\n"
	"        $method = Request::instance()->method();\n"
	"        return strtoupper($rule) == $method;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证时间和日期是否符合指定格式\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function dateFormat($value, $rule)\n"
	"    {\n"
	"        $info = date_parse_from_format($rule, $value);\n"
	"        return 0 == $info[\'warning_count\'] && 0 == $info[\'error_count\'];\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证是否唯一\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则 格式：数据表,字段名,排除ID,主键名\n"
	"     * @param array     $data  数据\n"
	"     * @param string    $field  验证字段名\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function unique($value, $rule, $data, $field)\n"
	"    {\n"
	"        if (is_string($rule)) {\n"
	"            $rule = explode(\',\', $rule);\n"
	"        }\n"
	"        if (false !== strpos($rule[0], \'\\\\\')) {\n"
	"            // 指定模型类\n"
	"            $db = new $rule[0];\n"
	"        } else {\n"
	"            try {\n"
	"                $db = Loader::model($rule[0]);\n"
	"            } catch (ClassNotFoundException $e) {\n"
	"                $db = Db::name($rule[0]);\n"
	"            }\n"
	"        }\n"
	"        $key = isset($rule[1]) ? $rule[1] : $field;\n"
	"\n"
	"        if (strpos($key, \'^\')) {\n"
	"            // 支持多个字段验证\n"
	"            $fields = explode(\'^\', $key);\n"
	"            foreach ($fields as $key) {\n"
	"                if (isset($data[$key])) {\n"
	"                    $map[$key] = $data[$key];\n"
	"                }\n"
	"            }\n"
	"        } elseif (strpos($key, \'=\')) {\n"
	"            parse_str($key, $map);\n"
	"        } elseif (isset($data[$field])) {\n"
	"            $map[$key] = $data[$field];\n"
	"        } else {\n"
	"            $map = [];\n"
	"        }\n"
	"\n"
	"        $pk = isset($rule[3]) ? $rule[3] : $db->getPk();\n"
	"        if (is_string($pk)) {\n"
	"            if (isset($rule[2])) {\n"
	"                $map[$pk] = [\'neq\', $rule[2]];\n"
	"            } elseif (isset($data[$pk])) {\n"
	"                $map[$pk] = [\'neq\', $data[$pk]];\n"
	"            }\n"
	"        }\n"
	"        if ($db->where($map)->field($pk)->find()) {\n"
	"            return false;\n"
	"        }\n"
	"        return true;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 使用行为类验证\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @param array     $data  数据\n"
	"     * @return mixed\n"
	"     */\n"
	"    protected function behavior($value, $rule, $data)\n"
	"    {\n"
	"        return Hook::exec($rule, \'\', $data);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 使用filter_var方式验证\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function filter($value, $rule)\n"
	"    {\n"
	"        if (is_string($rule) && strpos($rule, \',\')) {\n"
	"            list($rule, $param) = explode(\',\', $rule);\n"
	"        } elseif (is_array($rule)) {\n"
	"            $param = isset($rule[1]) ? $rule[1] : null;\n"
	"            $rule  = $rule[0];\n"
	"        } else {\n"
	"            $param = null;\n"
	"        }\n"
	"        return false !== filter_var($value, is_int($rule) ? $rule : filter_id($rule), $param);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证某个字段等于某个值的时候必须\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @param array     $data  数据\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function requireIf($value, $rule, $data)\n"
	"    {\n"
	"        list($field, $val) = explode(\',\', $rule);\n"
	"        if ($this->getDataValue($data, $field) == $val) {\n"
	"            return !empty($value) || \'0\' == $value;\n"
	"        } else {\n"
	"            return true;\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 通过回调方法验证某个字段是否必须\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @param array     $data  数据\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function requireCallback($value, $rule, $data)\n"
	"    {\n"
	"        $result = call_user_func_array($rule, [$value, $data]);\n"
	"        if ($result) {\n"
	"            return !empty($value) || \'0\' == $value;\n"
	"        } else {\n"
	"            return true;\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证某个字段有值的情况下必须\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @param array     $data  数据\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function requireWith($value, $rule, $data)\n"
	"    {\n"
	"        $val = $this->getDataValue($data, $rule);\n"
	"        if (!empty($val)) {\n"
	"            return !empty($value) || \'0\' == $value;\n"
	"        } else {\n"
	"            return true;\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证是否在范围内\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function in($value, $rule)\n"
	"    {\n"
	"        return in_array($value, is_array($rule) ? $rule : explode(\',\', $rule));\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证是否不在某个范围\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function notIn($value, $rule)\n"
	"    {\n"
	"        return !in_array($value, is_array($rule) ? $rule : explode(\',\', $rule));\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * between验证数据\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function between($value, $rule)\n"
	"    {\n"
	"        if (is_string($rule)) {\n"
	"            $rule = explode(\',\', $rule);\n"
	"        }\n"
	"        list($min, $max) = $rule;\n"
	"        return $value >= $min && $value <= $max;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 使用notbetween验证数据\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function notBetween($value, $rule)\n"
	"    {\n"
	"        if (is_string($rule)) {\n"
	"            $rule = explode(\',\', $rule);\n"
	"        }\n"
	"        list($min, $max) = $rule;\n"
	"        return $value < $min || $value > $max;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证数据长度\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function length($value, $rule)\n"
	"    {\n"
	"        if (is_array($value)) {\n"
	"            $length = count($value);\n"
	"        } elseif ($value instanceof File) {\n"
	"            $length = $value->getSize();\n"
	"        } else {\n"
	"            $length = mb_strlen((string) $value);\n"
	"        }\n"
	"\n"
	"        if (strpos($rule, \',\')) {\n"
	"            // 长度区间\n"
	"            list($min, $max) = explode(\',\', $rule);\n"
	"            return $length >= $min && $length <= $max;\n"
	"        } else {\n"
	"            // 指定长度\n"
	"            return $length == $rule;\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证数据最大长度\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function max($value, $rule)\n"
	"    {\n"
	"        if (is_array($value)) {\n"
	"            $length = count($value);\n"
	"        } elseif ($value instanceof File) {\n"
	"            $length = $value->getSize();\n"
	"        } else {\n"
	"            $length = mb_strlen((string) $value);\n"
	"        }\n"
	"        return $length <= $rule;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证数据最小长度\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function min($value, $rule)\n"
	"    {\n"
	"        if (is_array($value)) {\n"
	"            $length = count($value);\n"
	"        } elseif ($value instanceof File) {\n"
	"            $length = $value->getSize();\n"
	"        } else {\n"
	"            $length = mb_strlen((string) $value);\n"
	"        }\n"
	"        return $length >= $rule;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证日期\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @param array     $data  数据\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function after($value, $rule, $data)\n"
	"    {\n"
	"        return strtotime($value) >= strtotime($rule);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证日期\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @param array     $data  数据\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function before($value, $rule, $data)\n"
	"    {\n"
	"        return strtotime($value) <= strtotime($rule);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证日期字段\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @param array     $data  数据\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function afterWith($value, $rule, $data)\n"
	"    {\n"
	"        $rule = $this->getDataValue($data, $rule);\n"
	"        return !is_null($rule) && strtotime($value) >= strtotime($rule);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证日期字段\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @param array     $data  数据\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function beforeWith($value, $rule, $data)\n"
	"    {\n"
	"        $rule = $this->getDataValue($data, $rule);\n"
	"        return !is_null($rule) && strtotime($value) <= strtotime($rule);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证有效期\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function expire($value, $rule)\n"
	"    {\n"
	"        if (is_string($rule)) {\n"
	"            $rule = explode(\',\', $rule);\n"
	"        }\n"
	"        list($start, $end) = $rule;\n"
	"        if (!is_numeric($start)) {\n"
	"            $start = strtotime($start);\n"
	"        }\n"
	"\n"
	"        if (!is_numeric($end)) {\n"
	"            $end = strtotime($end);\n"
	"        }\n"
	"        return $_SERVER[\'REQUEST_TIME\'] >= $start && $_SERVER[\'REQUEST_TIME\'] <= $end;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证IP许可\n"
	"     * @access protected\n"
	"     * @param string    $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return mixed\n"
	"     */\n"
	"    protected function allowIp($value, $rule)\n"
	"    {\n"
	"        return in_array($_SERVER[\'REMOTE_ADDR\'], is_array($rule) ? $rule : explode(\',\', $rule));\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证IP禁用\n"
	"     * @access protected\n"
	"     * @param string    $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @return mixed\n"
	"     */\n"
	"    protected function denyIp($value, $rule)\n"
	"    {\n"
	"        return !in_array($_SERVER[\'REMOTE_ADDR\'], is_array($rule) ? $rule : explode(\',\', $rule));\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 使用正则验证数据\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则 正则规则或者预定义正则名\n"
	"     * @return mixed\n"
	"     */\n"
	"    protected function regex($value, $rule)\n"
	"    {\n"
	"        if (isset($this->regex[$rule])) {\n"
	"            $rule = $this->regex[$rule];\n"
	"        }\n"
	"        if (0 !== strpos($rule, \'/\') && !preg_match(\'/\\/[imsU]{0,4}$/\', $rule)) {\n"
	"            // 不是正则表达式则两端补上/\n"
	"            $rule = \'/^\' . $rule . \'$/\';\n"
	"        }\n"
	"        return is_scalar($value) && 1 === preg_match($rule, (string) $value);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证表单令牌\n"
	"     * @access protected\n"
	"     * @param mixed     $value  字段值\n"
	"     * @param mixed     $rule  验证规则\n"
	"     * @param array     $data  数据\n"
	"     * @return bool\n"
	"     */\n"
	"    protected function token($value, $rule, $data)\n"
	"    {\n"
	"        $rule = !empty($rule) ? $rule : \'__token__\';\n"
	"        if (!isset($data[$rule]) || !Session::has($rule)) {\n"
	"            // 令牌数据无效\n"
	"            return false;\n"
	"        }\n"
	"\n"
	"        // 令牌验证\n"
	"        if (isset($data[$rule]) && Session::get($rule) === $data[$rule]) {\n"
	"            // 防止重复提交\n"
	"            Session::delete($rule); // 验证完成销毁session\n"
	"            return true;\n"
	"        }\n"
	"        // 开启TOKEN重置\n"
	"        Session::delete($rule);\n"
	"        return false;\n"
	"    }\n"
	"\n"
	"    // 获取错误信息\n"
	"    public function getError()\n"
	"    {\n"
	"        return $this->error;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取数据值\n"
	"     * @access protected\n"
	"     * @param array $data 数据\n"
	"     * @param string $key 数据标识 支持二维\n"
	"     * @return mixed\n"
	"     */\n"
	"    protected function getDataValue($data, $key)\n"
	"    {\n"
	"        if (is_numeric($key)) {\n"
	"            $value = $key;\n"
	"        } elseif (strpos($key, \'.\')) {\n"
	"            // 支持二维数组验证\n"
	"            list($name1, $name2) = explode(\'.\', $key);\n"
	"            $value               = isset($data[$name1][$name2]) ? $data[$name1][$name2] : null;\n"
	"        } else {\n"
	"            $value = isset($data[$key]) ? $data[$key] : null;\n"
	"        }\n"
	"        return $value;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取验证规则的错误提示信息\n"
	"     * @access protected\n"
	"     * @param string    $attribute  字段英文名\n"
	"     * @param string    $title  字段描述名\n"
	"     * @param string    $type  验证规则名称\n"
	"     * @param mixed     $rule  验证规则数据\n"
	"     * @return string\n"
	"     */\n"
	"    protected function getRuleMsg($attribute, $title, $type, $rule)\n"
	"    {\n"
	"        if (isset($this->message[$attribute . \'.\' . $type])) {\n"
	"            $msg = $this->message[$attribute . \'.\' . $type];\n"
	"        } elseif (isset($this->message[$attribute][$type])) {\n"
	"            $msg = $this->message[$attribute][$type];\n"
	"        } elseif (isset($this->message[$attribute])) {\n"
	"            $msg = $this->message[$attribute];\n"
	"        } elseif (isset(self::$typeMsg[$type])) {\n"
	"            $msg = self::$typeMsg[$type];\n"
	"        } elseif (0 === strpos($type, \'require\')) {\n"
	"            $msg = self::$typeMsg[\'require\'];\n"
	"        } else {\n"
	"            $msg = $title . Lang::get(\'not conform to the rules\');\n"
	"        }\n"
	"\n"
	"        if (is_string($msg) && 0 === strpos($msg, \'{%\')) {\n"
	"            $msg = Lang::get(substr($msg, 2, -1));\n"
	"        } elseif (Lang::has($msg)) {\n"
	"            $msg = Lang::get($msg);\n"
	"        }\n"
	"\n"
	"        if (is_string($msg) && is_scalar($rule) && false !== strpos($msg, \':\')) {\n"
	"            // 变量替换\n"
	"            if (is_string($rule) && strpos($rule, \',\')) {\n"
	"                $array = array_pad(explode(\',\', $rule), 3, \'\');\n"
	"            } else {\n"
	"                $array = array_pad([], 3, \'\');\n"
	"            }\n"
	"            $msg = str_replace(\n"
	"                [\':attribute\', \':rule\', \':1\', \':2\', \':3\'],\n"
	"                [$title, (string) $rule, $array[0], $array[1], $array[2]],\n"
	"                $msg);\n"
	"        }\n"
	"        return $msg;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取数据验证的场景\n"
	"     * @access protected\n"
	"     * @param string $scene  验证场景\n"
	"     * @return array\n"
	"     */\n"
	"    protected function getScene($scene = \'\')\n"
	"    {\n"
	"        if (empty($scene)) {\n"
	"            // 读取指定场景\n"
	"            $scene = $this->currentScene;\n"
	"        }\n"
	"\n"
	"        if (!empty($scene) && isset($this->scene[$scene])) {\n"
	"            // 如果设置了验证适用场景\n"
	"            $scene = $this->scene[$scene];\n"
	"            if (is_string($scene)) {\n"
	"                $scene = explode(\',\', $scene);\n"
	"            }\n"
	"        } else {\n"
	"            $scene = [];\n"
	"        }\n"
	"        return $scene;\n"
	"    }\n"
	"\n"
	"    public static function __callStatic($method, $params)\n"
	"    {\n"
	"        $class = self::make();\n"
	"        if (method_exists($class, $method)) {\n"
	"            return call_user_func_array([$class, $method], $params);\n"
	"        } else {\n"
	"            throw new \\BadMethodCallException(\'method not exists:\' . __CLASS__ . \'->\' . $method);\n"
	"        }\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif